using System;
using System.Collections.Generic;
using System.Text;
using SEAM.Core;

namespace SEAM.Data
{
    /// <summary>
    /// Defines a class for DataAccessException
    /// 
    /// <remarks>
    /// This class provides detailed information on any exceptions that
    /// are generated while trying to utilize DataAccess capabilities.
    /// </remarks>
    /// 
    /// </summary>
    public class DataAccessException : SEAMException
    {
        /// <summary>
        /// Initializes a new instance of the DataAccessException 
        /// class with a specified error message.
        /// </summary>
        /// <param name="strMessage">The message that describes the error.</param>
        public DataAccessException(string strMessage) 
            : this(strMessage, null) { }

        /// <summary>
        /// Initializes a new instance of the DataAccessException 
        /// class with a specified error message while trying to
        /// execute a SQL statement.
        /// </summary>
        /// <param name="strMessage">The message that describes the error.</param>
        /// <param name="strSQL">SQL statement that generated the error.</param>
        public DataAccessException(string strMessage, string strSQL)
            : this(strMessage, strSQL, null) { }

        /// <summary>
        /// Initializes a new instance of the DataAccessException 
        /// class with a specified error message while trying to
        /// execute a SQL statement with parameters.
        /// </summary>
        /// <param name="strMessage">The message that describes the error.</param>
        /// <param name="strSQL">SQL statement that generated the error.</param>
        /// <param name="arrParams">Array of DataAccessParam objects used in the database command.</param>
        public DataAccessException(string strMessage, string strSQL, DataAccessParam[] arrParams)
            : this(strMessage, strSQL, arrParams, null) { }

        /// <summary>
        /// Initializes a new instance of the DataAccessException 
        /// class with a specified error message while trying to
        /// execute a SQL statement with parameters.
        /// </summary>
        /// <param name="strMessage">The message that describes the error.</param>
        /// <param name="strSQL">SQL statement that generated the error.</param>
        /// <param name="arrParams">Array of DataAccessParam objects used in the database command.</param>
        /// <param name="innerException">The exception that is the cause of the current exception.</param>
        public DataAccessException(string strMessage, string strSQL, DataAccessParam[] arrParams, Exception innerException)
            : base(strMessage, innerException)
        {
            if (!string.IsNullOrEmpty(strSQL))
                AdditionalInfo.Add("SQL Statement", strSQL);
       
            if (arrParams != null)
            {
                for (int i = 0; i < arrParams.Length; i++)
                    AdditionalInfo.Add(arrParams[i].DeclarationString, arrParams[i].ValueString);
            }
        }
    }
}
